Passed
Branch master (312c6c)
by Alejandro
02:34
created

selectedServer.js ➔ ???   A

Complexity

Conditions 1
Paths 0

Size

Total Lines 10
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 5
Bugs 0 Features 0
Metric Value
cc 1
c 5
b 0
f 0
nc 0
nop 1
dl 0
loc 10
ccs 4
cts 4
cp 1
crap 1
rs 10
eloc 1
1
import { createAction, handleActions } from 'redux-actions';
2
import { resetShortUrlParams } from '../../short-urls/reducers/shortUrlsListParams';
3
4
/* eslint-disable padding-line-between-statements */
5 1
export const SELECT_SERVER = 'shlink/selectedServer/SELECT_SERVER';
6 1
export const RESET_SELECTED_SERVER = 'shlink/selectedServer/RESET_SELECTED_SERVER';
7
/* eslint-enable padding-line-between-statements */
8
9 1
const initialState = null;
10
11 1
export const resetSelectedServer = createAction(RESET_SELECTED_SERVER);
12
13 2
export const selectServer = (serversService) => (serverId) => (dispatch) => {
14 2
  dispatch(resetShortUrlParams());
15
16 2
  const selectedServer = serversService.findServerById(serverId);
17
18 2
  dispatch({
19
    type: SELECT_SERVER,
20
    selectedServer,
21
  });
22
};
23
24
export default handleActions({
25 1
  [RESET_SELECTED_SERVER]: () => initialState,
26 1
  [SELECT_SERVER]: (state, { selectedServer }) => selectedServer,
27
}, initialState);
28